﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ec_System.Facade.Web;
using Ec_System.Models.Web;
using Ec_System.Bll.Web;
using Ec_System.Facade.Web;

namespace Ec_System.WebUI.Areas.Web.Controllers
{
    public class CommonUCController : Controller
    {
        ProductClassFacade facace = new ProductClassFacade();

       
        public ViewResult IndexMenu()
        {
            var model = facace.GetMenuData();
            return View(model);
        }

        
        public ViewResult Menu()
        {
            var model = facace.GetMenuData();
            return View(model);
        }

        /// <summary>
        /// 商品分类信息模块
        /// </summary>
        /// <param name="class1"></param>
        /// <param name="class2"></param>
        /// <param name="class3"></param>
        /// <returns></returns>
        
        public ActionResult ProductSearchByClass(int class1 = 0, int class2 = 0, int class3 = 0)
        {
            ProductClassManager productClass = new ProductClassManager();
            var model = productClass.GetSearchCondition(class1, class2, class3);
            ViewBag.Class1 = class1;
            ViewBag.Class2 = class2;
            ViewBag.Class3 = class3;

            return View(model);
        }

        /// <summary>
        /// 首页各个楼层展示模块
        /// </summary>
        /// <returns></returns>
        
        public ViewResult IndexFloor()
        {
            IndexRecommendManager indexRecommend = new IndexRecommendManager();
            var model = indexRecommend.GetIndexFloorData();

            return View(model);
        }
        /// <summary>
        /// 商品详情页模块
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
       
        public ActionResult ProductInfo_uc(int id)
        {
            VendorShopFacade vendorShop = new Facade.Web.VendorShopFacade();
            var model = vendorShop.GetProductInfoByID(id);

            if(model.PromotionSchedule == null)
            {
                return View("ProductInfo_uc", model);
            }
            //如果非空则该商品属于抢购商品
            else
            {
                //如果未True则抢购未开始
                if(DateTime.Now < model.PromotionSchedule.StartTime)
                {
                    DateTime baseTime = model.PromotionSchedule.StartTime;
                    //获取时间差
                    Double time = Math.Abs(DateTime.Now.Subtract(baseTime).TotalSeconds);
                    model.PromotionSchedule.ScheduleStatus = 0;
                    model.PromotionSchedule.RemainTimes = time;
                }
                //如果未True则抢购在进行中
                else if(DateTime.Now < model.PromotionSchedule.EndTime &&  DateTime.Now > model.PromotionSchedule.StartTime)
                {                   
                    DateTime baseTime = model.PromotionSchedule.EndTime;
                    var time = Math.Abs(DateTime.Now.Subtract(baseTime).TotalSeconds);
                    model.PromotionSchedule.ScheduleStatus = 1;
                    model.PromotionSchedule.RemainTimes = time;
                }
                else if(DateTime.Now > model.PromotionSchedule.EndTime)
                {
                    model.PromotionSchedule.ScheduleStatus = 3;
                }
                else
                {
                    model.PromotionSchedule.ScheduleStatus = 2;
                }
                return View("ProductInfoSchedule_uc", model);
            }           
        }



        public ViewResult Test()
        {
           
            return View();
        }
    }
}